package com.badlogic.androidgames.framework.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.badlogic.androidgames.framework.FileIO;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.os.Environment;
import android.preference.PreferenceManager;

/**
 * @deprecated:文件I/O
 * @author frank
 * @date 2015年11月30日
 */
public class AndroidFileIO implements FileIO {
	/**上下文**/
	Context context;
	/**资源管理器**/
	AssetManager assets;
	/**外部存储路径**/
	String externalStoragePath;
	
	public AndroidFileIO(Context context) {
		this.context = context;
		this.assets = context.getAssets();
		// Environment 环境	getExternalStorageDirectory 获得外部存储目录	getAbsolutePath 得到绝对路径	separator 分隔符
		this.externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
	}
	/**读取资源	Input 输入**/
	@Override
	public InputStream readAsset(String fileName) throws IOException {
		return assets.open(fileName);
	}
	/**读取文件	Input 输入**/
	@Override
	public InputStream readFile(String fileName) throws IOException {
		return new FileInputStream(externalStoragePath + fileName);
	}
	/**写入文件	Output 输出**/
	@Override
	public OutputStream writeFile(String fileName) throws IOException {
		return new FileOutputStream(externalStoragePath + fileName);
	}
	/**预设	Shared 共享	Preference 优先权**/
	public SharedPreferences getPreferences() {
		return PreferenceManager.getDefaultSharedPreferences(context);
	}
	
}
